/*
 * Copyright 2009 Johnson Consulting Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package com.johnsoncs.gwt.widgets.samples.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.johnsoncs.gwt.widgets.client.util.Elements;

/**
 * @author wilj
 *
 */
public class FadeDemo extends Composite {
	public FadeDemo() {
		final VerticalPanel panel = new VerticalPanel();
		final Image image = new Image("images/vancouver.jpg");
		final HorizontalPanel buttonPanel = new HorizontalPanel();
		final Button fadeIn = new Button("Fade In");
		final Button fadeOut = new Button("Fade Out");

		fadeOut.setEnabled(false);

		panel.add(buttonPanel);
		buttonPanel.add(fadeIn);
		buttonPanel.add(fadeOut);

		image.setVisible(false);
		panel.add(image);

		fadeIn.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(final ClickEvent event) {
				fadeIn.setEnabled(false);
				Elements.fadeIn(image, 2000, new Elements.FadeCallback() {
					@Override
					public boolean isCanceled() {
						return false;
					}

					@Override
					public void onFadeComplete() {
						fadeOut.setEnabled(true);
					}

					@Override
					public void onFadeStart() {
						image.setVisible(true);
					}
				});
			}
		});

		fadeOut.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(final ClickEvent event) {
				fadeOut.setEnabled(false);
				Elements.fadeOut(image, 2000, new Elements.FadeCallback() {
					@Override
					public boolean isCanceled() {
						return false;
					}

					@Override
					public void onFadeComplete() {
						fadeIn.setEnabled(true);
					}

					@Override
					public void onFadeStart() {
						// do nothing
					}
				});
			}
		});

		super.initWidget(panel);
	}
}
